package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.constant.StatusConstant;
import com.example.demo.entity.Gift;
import com.example.demo.entity.GiftWheelVo;
import com.example.demo.mapper.GiftMapper;
import com.example.demo.result.Result;
import com.example.demo.service.GiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GiftServiceImpl implements GiftService {

    @Autowired
    private GiftMapper giftMapper;
    @Override
    public Result<List<GiftWheelVo>> getAllGift() {
        QueryWrapper<Gift> giftQueryWrapper = new QueryWrapper<>();
        giftQueryWrapper.select("gift_name").ne("gift_id", StatusConstant.NO_GIFT);
        List<Gift> giftList = giftMapper.selectList(giftQueryWrapper);
        giftList.forEach(System.out::println);
        List<GiftWheelVo> giftWheelVoList = new ArrayList<>();
        for (Gift g : giftList) {
            GiftWheelVo gift = new GiftWheelVo();
            gift.setGiftName(g.getGiftName());
            GiftWheelVo noGift = new GiftWheelVo();
            noGift.setGiftName(StatusConstant.NO_GIFT_NAME);
            giftWheelVoList.add(gift);
            giftWheelVoList.add(noGift);
        }
        return Result.success(giftWheelVoList);
    }
}
